package com.simple.space.web.controller;

import com.simple.space.common.constant.Result;
import com.simple.space.modules.test.pojo.Test;
import com.simple.space.modules.test.pojo.Goods;
import com.simple.space.modules.test.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @ClassName TestController
 * @Author SimpleTree
 **/
@RestController
@RequestMapping("/test")
public class TestController {

    @Autowired
    private TestService testService;

    @PostMapping("/add")
    public Result add(String name) {
        Test test = new Test();
        test.setName(name);
        testService.add(test);
        return new Result(200, "成功");
    }

    /**
     * {
     *     "stock":[{
     *         "goodsId":"1001",
     *         "name":"苹果手机",
     *         "number":"2"
     *     },{
     *         "goodsId":"1002",
     *         "name":"华为",
     *         "number":"5"
     *     },{
     *         "goodsId":"1003",
     *         "name":"小米",
     *         "number":"3"
     *     },{
     *         "goodsId":"1004",
     *         "name":"天音",
     *         "number":"12"
     *     }],
     *     "order":[{
     *         "goodsId":"1001",
     *         "name":"苹果手机",
     *         "number":"1"
     *     },{
     *         "goodsId":"1002",
     *         "name":"华为",
     *         "number":"2"
     *     },,{
     *         "goodsId":"1003",
     *         "name":"小米",
     *         "number":"3"
     *     },{
     *         "goodsId":"1004",
     *         "name":"天音",
     *         "number":"4"
     *     }]
     * }
     * @param map
     * @return
     */
    @GetMapping("/save")
    public Result save(@RequestBody Map map) {
        List<Map<String,String>> stock =(List<Map<String,String>>) map.get("stock");
        List<Map<String,String>> order = (List<Map<String,String>>) map.get("order");

        List<Goods> stocks = testService.saveGoods(stock, order);
        return new Result(200, "成功",stocks);
    }


}
